package com.sun.abilities.collection;

import java.util.Iterator;
import java.util.Stack;

import org.junit.Test;

public class StackTest {
	@Test
	public void test1() {
		Stack<StackNode> stack = new Stack<StackNode>();
		for (int i = 0; i < 5; i++) {
			stack.push(new StackNode(i + "", "name" + i));
		}
		stack.empty();
		System.out.println(stack);
//		打印栈顶元素
		System.out.println(stack.peek());
		System.out.println(stack.peek());
//		栈顶元素出栈		
		System.out.println(stack.pop());
		System.out.println(stack);
	}
	
	@Test
	public void test2() {
		Stack<StackNode> stack = new Stack<StackNode>();
		for (int i = 0; i < 5; i++) {
			stack.add(new StackNode(i + "", "name" + i));
		}
		System.out.println(stack);
	}
	
	@Test
	public void test3() {
		Stack<StackNode> stack = new Stack<StackNode>();
		for (int i = 0; i < 5; i++) {
			stack.add(new StackNode(i + "", "name" + i));
		}
		Iterator<StackNode> nodes = stack.iterator();
		System.out.println(stack);
	}
}

class StackNode {
	private String id;
	private String name;

	public StackNode(String id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "[id=" + id + ", name=" + name + "]";
	}
}